<?php

	if(!empty($_POST)){
		// print_r($_POST['check']);exit;
			 //把表单的值存放到这两个变量中
		 $name=$_POST['name'];
		 $password=$_POST['password'];

                  //判断验证码是否输入正确
				if(trim(strtolower($_POST['code']))!=trim(strtolower($_SESSION['code']))){
					// echo 1;exit;
                      echo '<script>alert("连接失败");history.go(-1) </script>';die;
				}



				 if(!empty($_COOKIE['password'])&&$_COOKIE['password']==$_POST['password']){

					$password=$_COOKIE['password'];
				 }



		//这里缺少对数据库链接的优化处理要补上 李哥笔


					 //把符合条件的记录查询出来
		$sql="SELECT * FROM  `admin` where `name` = '$name' and `password` = '$password'";
					 //定义一个变量存放结果集
		$data=mysqli_query($link,$sql);

						//mysqli_fetch_assoc是从结果集获取数据
		$result=mysqli_fetch_assoc($data);




		if(!empty($result)){


		if(!empty($_POST['check'])){

				 setcookie('name',$name,time()+3600*24*7);

						 setcookie('password',$password,time()+3600*24*7);

			}else{

				setcookie('name','',-1);
				setcookie('password','del.php',-1);
			}



				$_SESSION['admin'] = $result;

			 header('location:index.php?c=index&a=index&admin=1');


		}else{

			echo '<script>alert("连接失败");history.go(-1) </script>';
		}

	}
include_once ('protected/View/admin/admin/login1.html');

?>

